import logging

import pytest

from resource.pom.smart_perf import SmartPerf
from utils.manager import Images


class Test:
    app = SmartPerf

    @pytest.mark.parametrize('setup_teardown', [app.bundle_name], indirect=True)
    def test(self, setup_teardown, device):
        "启动或反复启动SmartPerf应用无卡死、黑屏、白屏等现象"
        for i in range(5):
            logging.info('步骤1.{}：打开或反复启动SmartPerf应用'.format(i))
            device.start_ability(self.app.bundle_name, self.app.ability_name)
            logging.info('预期结果1.{}：SmartPerf打开无卡死、黑屏、白屏等现象'.format(i))
            device.assert_current_window(self.app.window_name)
            if i == 4:
                snap_shot = device.save_snapshot_to_local('smart_perf.jpeg')
                Images.crop_picture(snap_shot)
                similarity = Images.compare_image_similarity(snap_shot, self.app.standard_pic)
                assert similarity > 0.6, '启动页面异常'
            device.go_back()
